{include file='header'/}
<body>
<form class="layui-form" action="javascript:;" onsubmit="return dosub(this)">
    <div class="mainBox">
        <div class="main-container layui-container">
            <div class="layui-form-item">
                <label class="layui-form-label required">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" lay-verify="required|username" autocomplete="off"
                           placeholder="请输入用户名"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" lay-verify="required|pwd" autocomplete="off"
                           placeholder="请输入密码"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">角色组</label>
                <div class="layui-input-block">
                    {foreach role_group_name as $key=>$val}
                    <input type="checkbox" id="auth_ids" name="auth_ids[]" lay-skin="primary" title="{$val}"
                           lay-verify="required" value="{$key}">
                    {/foreach}
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">昵称</label>
                <div class="layui-input-block">
                    <input type="text" name="nick_name" lay-verify="required" autocomplete="off"
                           placeholder="请输入昵称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item huicmf-upload">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-block">
                    <input type="text" name="avatar" value=""
                           onmouseover="hui_img_preview('avatar-select-input',this.value)"
                           onmouseout="layer.closeAll();" id="avatar-select-input" autocomplete="off"
                           class="layui-input">
                    <button type="button" class="layui-btn layui-btn-normal layUpload" id="picker_pic"
                            data-multiple="false" data-input-id="avatar-select-input"
                            data-preview-id="image" data-type="image"><i class="layui-icon"></i>上传图片
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="email" lay-verify="email" autocomplete="off" placeholder="请输入邮箱"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="启用" checked>
                    <input type="radio" name="status" value="0" title="禁用">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

{include file='footer'/}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;

    let $ = layui.jquery;
    form.verify({
      username: ui_rule.username,
      pwd: ui_rule.password,
    });

    window.dosub = function (obj) {
      var loading = layer.load(2);
      $.ajax({
        url: "{:url('admin/add')}",
        data: $(obj).serialize(),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (res) {
          layer.close(loading);
          if (res.code === 200) {
            hui_msg(res.msg, 1, function () {
              var pageId = parent.layer.getFrameIndex (window.name);
              parent.layer.close(pageId);
            });
          } else {
            hui_msg(res.msg, 2);
          }
        }
      })
      return false;
    }
  })
</script>
<script>
</script>
</body>
</html>
